﻿using FDStudio.Core.Entities.Query;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace FDStudio.Core.Extensions
{
    /*
     CreatedOn: 2018-01-30
     CreatedBy: Jackie Lee(天宇遊龍)
     */
    /// <summary>
    /// 排序扩展
    /// </summary>
    public static class IQueryOrderExtension
    {
        /// <summary>
        /// 升序
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="Q"></typeparam>
        /// <param name="target"></param>
        /// <param name="orderby"></param>
        /// <returns></returns>
        public static IQueryOrder<T> SortBy<T, Q>(this IEnumerable<T> target, Expression<Func<T, Q>> orderby) where T : class
        {
            return new QueryOrder<T>().OrderBy(orderby);
        }

        /// <summary>
        /// 降序
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="Q"></typeparam>
        /// <param name="target"></param>
        /// <param name="orderby"></param>
        /// <returns></returns>
        public static IQueryOrder<T> SortByDescending<T, Q>(this IEnumerable<T> target, Expression<Func<T, Q>> orderby) where T : class
        {
            return new QueryOrder<T>().OrderBy(orderby);
        }
    }
}
